﻿package mortal.game.scene3D.display3d.text3d.dynamicText3d
{
    import baseEngine.core.*;
    import flash.events.*;
    import flash.text.*;
    import flash.utils.*;
    import mortal.game.scene3D.*;

    public class Text3DFactory extends Object
    {
        private var _scene:GameScene3D;
        private var _dicMap:Dictionary;
        public static const instance:Text3DFactory = new Text3DFactory;

        public function Text3DFactory()
        {
            this._dicMap = new Dictionary(false);
            this._dicMap[32] = new WidthType(32);
            this._dicMap[64] = new WidthType(64);
            this._dicMap[128] = new WidthType(128);
            this._dicMap[256] = new WidthType(256);
            this._dicMap[512] = new WidthType(512);
            return;
        }// end function

        public function checkToDispose(event:Event = null) : void
        {
            var _loc_2:WidthType = null;
            var _loc_3:Boolean = false;
            for each (_loc_2 in this._dicMap)
            {
                
                _loc_3 = _loc_2.checkAndDispose();
            }
            return;
        }// end function

        public function checkToUploadTexture() : void
        {
            var _loc_1:WidthType = null;
            if (!this._scene)
            {
                return;
            }
            for each (_loc_1 in this._dicMap)
            {
                
                if (_loc_1.checkAndUpload(this._scene))
                {
                    return;
                }
            }
            return;
        }// end function

        public function init(param1:GameScene3D) : void
        {
            var _loc_2:WidthType = null;
            this._scene = param1;
            Text3DRender.instance.init(param1);
            for each (_loc_2 in this._dicMap)
            {
                
                _loc_2.init(this._scene);
            }
            return;
        }// end function

        public function reinit(param1:GameScene3D) : void
        {
            var _loc_2:WidthType = null;
            Text3DRender.instance.reinit(param1);
            for each (_loc_2 in this._dicMap)
            {
                
                _loc_2.reinit(this._scene);
            }
            return;
        }// end function

        public function createtext3D(param1:TextField, param2:Boolean, param3:Pivot3D) : Text3D
        {
            var _loc_4:* = this.getWidthType(param1.textWidth + 4);
            return _loc_4.createText3D(param1, param2, param3);
        }// end function

        public function updateText3D(param1:Text3D, param2:TextField, param3:Pivot3D) : void
        {
            var _loc_4:* = this.getWidthType(param2.textWidth + 4);
            _loc_4.updateText3D(param1, param2, param3);
            return;
        }// end function

        private function getWidthType(param1:int) : WidthType
        {
            var _loc_2:int = 0;
            if (param1 < 32)
            {
                _loc_2 = 32;
            }
            else if (param1 > 512)
            {
                _loc_2 = 512;
            }
            else
            {
                _loc_2 = 1;
                while (_loc_2 << 1 <= param1)
                {
                    
                    _loc_2 = _loc_2 << 1;
                }
                if (param1 > _loc_2)
                {
                    _loc_2 = _loc_2 * 2;
                }
            }
            return this._dicMap[_loc_2];
        }// end function

        public function disposeText3D(param1:Text3D) : void
        {
            if (param1.parent)
            {
                param1.parent = null;
            }
            param1.bigImg.disposeText3D(param1);
            return;
        }// end function

    }
}
